#!/usr/bin/perl
# Copyright (C) 2006 by Moritz Lenz <moritz@faui2k3.org>
# License: see file LICENSE (in short: Artistic or GPL, same terms as with the
# perl interpreter).
use warnings;
use strict;

my @perm = ([0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], 
		[2, 1, 0]);
my @a = (0 .. 8);
open(OUT, ">", 'perm.h') or die "Can't write to 'perm.h': $!";
print OUT <<HEADER;
/* perm.h
 * Copyright (C) 2006 be Moritz Lenz. License: see file LICENSE (in short:
 * artistic or GPL) 
 *
 * Contains 6^4 permutations of numbers 0 ... 8
 * permutations are blockwise (0 1 2 3... 0 2 1 3 ... 1 0 2 3 ...) and these 
 * blocks are permuted.
 * 
 * This file is automatically generated by permuation.pl. Don't edit this file
 * directly, all changes will be lost on running `make`. */
HEADER

print OUT "static const int perm[1296][9] = {\n";

my @res = (0 .. 8);
foreach my $e (0 .. 5){
	foreach my $b (0 .. 5){
		foreach my $c (0 .. 5){
			foreach my $d (0 .. 5){
				my @r = (0 .. 8);
				$res[0] = $perm[$b][0];
				$res[1] = $perm[$b][1];
				$res[2] = $perm[$b][2];
				$res[3] = $perm[$c][0] + 3;
				$res[4] = $perm[$c][1] + 3;
				$res[5] = $perm[$c][2] + 3;
				$res[6] = $perm[$d][0] + 6;
				$res[7] = $perm[$d][1] + 6;
				$res[8] = $perm[$d][2] + 6;
				$r[0] = $res[3*$perm[$e][0]];
				$r[1] = $res[3*$perm[$e][0] + 1];
				$r[2] = $res[3*$perm[$e][0] + 2];
				$r[3] = $res[3*$perm[$e][1]];
				$r[4] = $res[3*$perm[$e][1] + 1];
				$r[5] = $res[3*$perm[$e][1] + 2];
				$r[6] = $res[3*$perm[$e][2]];
				$r[7] = $res[3*$perm[$e][2] + 1];
				$r[8] = $res[3*$perm[$e][2] + 2];
				print OUT "\t{", join ', ', @r;
				print OUT "},\n";
			}
		}
	}
}




print OUT "};\n";
close OUT;

